home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 June / PCWorld_2007-06_cd.bin / v cisle / tclock / tclocklight-040702-3.exe / source / common / mousestruct.c < prev    next >
C/C++ Source or Header  |  2004-03-06  |  7KB  |  246 lines

  1. /*-------------------------------------------------------------
  2.   mousestruct.c : load and save MOUSESTRUCT
  3.   (C) 1997-2003 Kazuto Sato
  4.   Please read readme.txt about the license.
  5.   
  6.   Written by Kazubon, Nanashi-san
  7. ---------------------------------------------------------------*/
  8.  
  9. #include "common.h"
  10. #include "command.h"
  11.  
  12. /* Globals */
  13.  
  14. void LoadMouseFunc(PMOUSESTRUCT pMSS, int count);
  15. void SaveMouseFunc(PMOUSESTRUCT pMSS, int count);
  16. void ImportOldMouseFunc(void);
  17.  
  18. /*------------------------------------------------
  19.   read settings of Mouse
  20. --------------------------------------------------*/
  21. void LoadMouseFunc(PMOUSESTRUCT pMSS, int count)
  22. {
  23.     int i;
  24.     char section[20], s[20];
  25.     
  26.     for(i = 0; i < count; i++)
  27.     {
  28.         wsprintf(section, "Mouse%d", i + 1);
  29.         
  30.         memset(pMSS + i, 0, sizeof(MOUSESTRUCT));
  31.         
  32.         GetMyRegStr(section, "Name", pMSS[i].name, BUFSIZE_NAME, section);
  33.         
  34.         GetMyRegStr(section, "Button", s, 20, "");
  35.         if(strcmp(s, "left") == 0) pMSS[i].nButton = 0;
  36.         else if(strcmp(s, "right") == 0) pMSS[i].nButton = 1;
  37.         else if(strcmp(s, "middle") == 0) pMSS[i].nButton = 2;
  38.         else if(strcmp(s, "x1") == 0) pMSS[i].nButton = 3;
  39.         else if(strcmp(s, "x2") == 0) pMSS[i].nButton = 4;
  40.         
  41.         pMSS[i].nClick = GetMyRegLong(section, "Click", 1);
  42.         pMSS[i].bCtrl  = GetMyRegLong(section, "Ctrl", FALSE);
  43.         pMSS[i].bShift = GetMyRegLong(section, "Shift", FALSE);
  44.         pMSS[i].bAlt   = GetMyRegLong(section, "Alt", FALSE);
  45.         
  46.         pMSS[i].nCommand = GetMyRegLong(section, "Command", 0);
  47.         GetMyRegStr(section, "Option", pMSS[i].option, MAX_PATH, "");
  48.     }
  49. }
  50.  
  51. /*------------------------------------------------
  52.   save settings of Mouse
  53. --------------------------------------------------*/
  54. void SaveMouseFunc(PMOUSESTRUCT pMSS, int count)
  55. {
  56.     int i;
  57.     char section[20];
  58.     
  59.     for(i = 0; i < count; i++)
  60.     {
  61.         wsprintf(section, "Mouse%d", i + 1);
  62.         
  63.         SetMyRegStr(section, "Name", pMSS[i].name);
  64.         
  65.         if(pMSS[i].nButton == 0)
  66.             SetMyRegStr(section, "Button", "left");
  67.         else if(pMSS[i].nButton == 1)
  68.             SetMyRegStr(section, "Button", "right");
  69.         else if(pMSS[i].nButton == 2)
  70.             SetMyRegStr(section, "Button", "middle");
  71.         else if(pMSS[i].nButton == 3)
  72.             SetMyRegStr(section, "Button", "x1");
  73.         else if(pMSS[i].nButton == 4)
  74.             SetMyRegStr(section, "Button", "x2");
  75.         
  76.         SetMyRegLong(section, "Click", pMSS[i].nClick);
  77.         SetMyRegLong(section, "Ctrl", pMSS[i].bCtrl);
  78.         SetMyRegLong(section, "Shift", pMSS[i].bShift);
  79.         SetMyRegLong(section, "Alt", pMSS[i].bAlt);
  80.         
  81.         SetMyRegLong(section, "Command", pMSS[i].nCommand);
  82.         SetMyRegStr(section, "Option", pMSS[i].option);
  83.     }
  84. }
  85.  
  86. // old mouse functions
  87. #define MOUSEFUNC_NONE       -1
  88. #define MOUSEFUNC_DATETIME    0
  89. #define MOUSEFUNC_EXITWIN     1
  90. #define MOUSEFUNC_RUNAPP      2
  91. #define MOUSEFUNC_MINALL      3
  92. #define MOUSEFUNC_SYNCTIME    4
  93. #define MOUSEFUNC_TIMER       5
  94. #define MOUSEFUNC_CLIPBOARD   6
  95. #define MOUSEFUNC_SCREENSAVER 7
  96. #define MOUSEFUNC_KYU         8
  97. #define MOUSEFUNC_DELRECDOCS  9
  98. #define MOUSEFUNC_PROPERTY    10
  99. #define MOUSEFUNC_CALENDAR    11
  100. #define MOUSEFUNC_STARTMENU   12
  101. #define MOUSEFUNC_TASKSW      13
  102. #define MOUSEFUNC_SHOWDESK    14
  103. #define MOUSEFUNC_LOCKPC      15
  104. #define MOUSEFUNC_MENU        16
  105. #define MOUSEFUNC_CHANGECONF  17
  106. #define MOUSEFUNC_VOLMUTE     18
  107. #define MOUSEFUNC_VOLSET      19
  108. #define MOUSEFUNC_VOLUD       20
  109. #define MOUSEFUNC_MONOFF      21
  110. #define MOUSEFUNC_CDOPEN      22
  111. #define MOUSEFUNC_CDCLOSE     23
  112. #define MOUSEFUNC_NETINIT     24
  113. #define MOUSEFUNC_DELUS       25
  114. #define MOUSEFUNC_FILELIST    26
  115. #define MOUSEFUNC_OPENFILE    100
  116.  
  117. static int oldToNew[] = {
  118.     IDC_DATETIME,
  119.     IDC_EXITWIN,
  120.     IDC_RUNAPP,
  121.     IDC_MINALL,
  122.     IDC_SYNCTIME,
  123.     IDC_TIMER,
  124.     IDC_MOUSECOPY,
  125.     IDC_SCREENSAVER,
  126.     IDC_KYU,
  127.     IDC_DELRECDOCS,
  128.     IDC_SHOWPROP,
  129.     IDC_SHOWCALENDER,
  130.     IDC_SHOWSTARTMENU,
  131.     IDC_TASKSW,
  132.     IDC_SHOWDESK,
  133.     IDC_LOCKPC,
  134.     IDC_TCLOCKMENU,
  135.     IDC_CHANGECONF,
  136.     IDC_VOLMUTE,
  137.     IDC_VOLSET,
  138.     IDC_VOLUD,
  139.     IDC_MONOFF,
  140.     IDC_CDOPEN,
  141.     IDC_CDCLOSE,
  142.     IDC_NETINIT,
  143.     IDC_DELUS,
  144.     IDC_FILELIST
  145. };
  146.  
  147. /*-----------------------------------------------------------
  148.   save old data (TClock 2.3.0 and TClock2ch) with new format
  149. ------------------------------------------------------------*/
  150. void ImportOldMouseFunc(void)
  151. {
  152.     char oldentry[20], newsection[20], s[MAX_PATH];
  153.     int i, j, k, count, nfunc;
  154.     char *oldoptions[] = { "%d%dFile", "%d%dClip",
  155.         "%d%dVol", "%d%dDrv" , "%d%dDelay", NULL, };
  156.     
  157.     count = 0;
  158.     for(i = 0; i <= 21; i++)
  159.     {
  160.         if(i == 15) continue;
  161.         
  162.         for(j = 1; j <= 4; j++)
  163.         {
  164.             wsprintf(oldentry, "%d%d", i, j);
  165.             nfunc = GetMyRegLong("Mouse", oldentry, -1);
  166.             if((0 <= nfunc && nfunc <= MOUSEFUNC_FILELIST) ||
  167.                 nfunc == MOUSEFUNC_OPENFILE)
  168.             {
  169.                 DelMyReg("Mouse", oldentry);
  170.                 
  171.                 wsprintf(newsection, "Mouse%d", count + 1);
  172.                 
  173.                 if(i == 0 || i == 5 || i == 10)
  174.                     SetMyRegStr(newsection, "Button", "left");
  175.                 else if(i == 1 || i == 6 || i == 11)
  176.                     SetMyRegStr(newsection, "Button", "right");
  177.                 else if(i == 2 || i == 7 || i == 12)
  178.                     SetMyRegStr(newsection, "Button", "middle");
  179.                 else if(i == 3 || i == 8 || i == 13)
  180.                     SetMyRegStr(newsection, "Button", "x1");
  181.                 else if(i == 4 || i == 9 || i == 14)
  182.                     SetMyRegStr(newsection, "Button", "x2");
  183.                 else
  184.                     strcpy(newsection, "Wheel");
  185.                 
  186.                 if(i <= 14)
  187.                     SetMyRegLong(newsection, "Click", j);
  188.                 
  189.                 if((5 <= i && i <= 9) || i == 18 || i == 19)
  190.                     SetMyRegLong(newsection, "Ctrl", TRUE);
  191.                 if((10 <= i && i <= 14) || i == 20 || i == 21)
  192.                     SetMyRegLong(newsection, "Shift", TRUE);
  193.                 
  194.                 if(nfunc == MOUSEFUNC_OPENFILE)
  195.                     SetMyRegLong(newsection, "Command", IDC_OPENFILE);
  196.                 else if(nfunc == MOUSEFUNC_TIMER)
  197.                 {
  198.                     SetMyRegLong(newsection, "Command", IDC_OPENFILE);
  199.                     SetMyRegStr(newsection, "Option", "tctimer.exe");
  200.                 }
  201.                 else if(nfunc == MOUSEFUNC_PROPERTY)
  202.                 {
  203.                     SetMyRegLong(newsection, "Command", IDC_OPENFILE);
  204.                     SetMyRegStr(newsection, "Option", "tcprop.exe");
  205.                 }
  206.                 else
  207.                     SetMyRegLong(newsection, "Command", oldToNew[nfunc]);
  208.                 
  209.                 for(k = 0; oldoptions[k]; k++)
  210.                 {
  211.                     wsprintf(oldentry, oldoptions[k], i, j);
  212.                     if(GetMyRegStr("Mouse", oldentry, s, MAX_PATH, "") > 0)
  213.                     {
  214.                         SetMyRegStr(newsection, "Option", s);
  215.                         DelMyReg("Mouse", oldentry);
  216.                     }
  217.                 }
  218.                 
  219.                 count++;
  220.             }
  221.             else
  222.             {
  223.                 if(i == 0 && j == 2) // double click
  224.                 {
  225.                     wsprintf(newsection, "Mouse%d", count + 1);
  226.                     SetMyRegStr(newsection, "Button", "left");
  227.                     SetMyRegLong(newsection, "Click", 2);
  228.                     SetMyRegLong(newsection, "Command", IDC_DATETIME);
  229.                     count++;
  230.                 }
  231.                 if(i == 1 && j == 1) // right single click
  232.                 {
  233.                     wsprintf(newsection, "Mouse%d", count + 1);
  234.                     SetMyRegStr(newsection, "Button", "right");
  235.                     SetMyRegLong(newsection, "Click", 1);
  236.                     SetMyRegLong(newsection, "Command", IDC_TCLOCKMENU);
  237.                     count++;
  238.                 }
  239.             }
  240.             if(i >= 16) break;
  241.         }
  242.     }
  243.     
  244.     SetMyRegLong("Mouse", "MouseNum", count);
  245. }
  246.